﻿using GEPL.InterfaceLibrary;
using GEPL.StandardModulesLibrary.ViewModels.Turtle;
using GEPL.StandardModulesLibrary.Views.Turtle;
using System;
using System.Runtime.Serialization;

namespace GEPL.StandardModulesLibrary.Elements.Turtle
{
    [Serializable]
    public class PenUpDownElement : IElement
    {
        private readonly PenUpDownViewModel viewModel;

        public PenUpDownElement()
        {
            viewModel = new PenUpDownViewModel();
        }

        public PenUpDownElement(SerializationInfo info, StreamingContext context)
        {
            viewModel = new PenUpDownViewModel()
            {
                Up = info.GetBoolean(nameof(viewModel.Up)),
                Down = info.GetBoolean(nameof(viewModel.Down))
            };
        }

        public ElementType ElementType
        {
            get { return ElementType.NormalStatement; }
        }

        public ProjectType ProjectType
        {
            get { return ProjectType.TurtleGraphics; }
        }

        public string ElementName
        {
            get { return Properties.Resources.Names_PenUpDown; }
        }

        public object Data
        {
            get { return viewModel; }
        }

        public Type UserControlType
        {
            get { return typeof(PenUpDownView); }
        }

        public string GetScript()
        {
            return viewModel.Up ? "Turtle.PenUp()" : "Turtle.PenDown()";
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue(nameof(viewModel.Up), viewModel.Up);
            info.AddValue(nameof(viewModel.Down), viewModel.Down);
        }
    }
}